using System;
using System.Collections.Generic;
using System.Diagnostics.SymbolStore;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
//using System.Xml.Serialization;
using ACS.Debugger.Core.Impl;
using ACS.Debugger.Core.Interfaces;
using ACS.Debugger.Core.NativeMethods;
using ACS.Debugger.DebugInfo;

namespace ACS.Tests
{
    class Program
    {
        private enum CreateProcessFlags 
        {
            CREATE_NEW_CONSOLE = 0x00000010,
            DEBUG_PROCESS = 3, //DEBUG_PROCESS|DEBUG_ONLY_THIS_PROCESS
        }

      //  public static ICorDebugBreakpoint Mybr;
        static void Main(string[] args)
        {

            new Debugger.Core.Wrappers.Debugger().StartAndSetBreakPoint();
            //ICorDebug debug = Debugging.GetDebugger();
            
            //debug.Initialize();
            /*
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();

            STARTUPINFO si = new STARTUPINFO();
            si.cb = Marshal.SizeOf(si);

            // initialize safe handles 
            si.hStdInput = new Microsoft.Win32.SafeHandles.SafeFileHandle(new IntPtr(0), false);
            si.hStdOutput = new Microsoft.Win32.SafeHandles.SafeFileHandle(new IntPtr(0), false);
            si.hStdError = new Microsoft.Win32.SafeHandles.SafeFileHandle(new IntPtr(0), false);            


            M m = new M();
            
            debug.SetManagedHandler(m);
            System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                
                debug.CreateProcess(
<<<<<<< .mine
                          @"C:\kurs\ACS.SampleCode\bin\Debug\acs.samplecode.exe", //lpApplicationName,
                          @"C:\kurs\ACS.SampleCode\bin\Debug\acs.samplecode.exe", //lpCommandLine,
=======
                          @"..\..\..\ACS.SampleCode\bin\Debug\acs.samplecode.exe", //lpApplicationName,
                          @"..\..\..\ACS.SampleCode\bin\Debug\acs.samplecode.exe", //lpCommandLine,
>>>>>>> .r57
                          null, //lpProcessAttributes,
                          null, //lpThreadAttributes,
                          1, //bInheritHandles,
                          (uint) 0,//CreateProcessFlags.CREATE_NEW_CONSOLE, //dwCreationFlags,
                          new IntPtr(0), //lpEnvironment,
<<<<<<< .mine
                          @"C:\kurs\ACS.SampleCode\bin\Debug",
=======
                          @"..\..\..\ACS.SampleCode\bin\Debug",
>>>>>>> .r57
                          si, //lpStartupInfo,
                          pi, //lpProcessInformation,
                          CorDebugCreateProcessFlags.DEBUG_NO_SPECIAL_OPTIONS,
                          out m.process
                );
                Debugging.CloseHandle(pi.hProcess);
                Debugging.CloseHandle(pi.hThread);


            } catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }

            //T Myth = new T();
            B Mybr = new B();
            //ICorDebugBreakpoint Mybr;
          
           m.Breakpoint(null, null, Mybr);
            
            while(true)
            {
<<<<<<< .mine
=======
                Console.ReadLine();
                try
                {
                    m.process.Terminate(1);
                } catch (Exception e)
                {
                    
                }
>>>>>>> .r57
            }
             */
        }
    }
    /*


    public class M : ICorDebugManagedCallback, ICorDebugManagedCallback2
    {
        public ICorDebugProcess process;

        public void Breakpoint(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, ICorDebugBreakpoint pBreakpoint)
        {
            // int i = 0;
            //long hr;
            pBreakpoint.Activate(0);
            
            //pBreakpoint.IsActive(out i);
            //Console.WriteLine(i);
            process.Continue(0);
        }

        public void StepComplete(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, ICorDebugStepper pStepper,
                                 CorDebugStepReason reason)
        {
            process.Continue(0);
             
        }

        public void Break(ICorDebugAppDomain pAppDomain, ICorDebugThread thread)
        { 
            process.Continue(0);
             
        }

        public void Exception(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, int unhandled)
        {
            process.Continue(0);
             
        }

        public void EvalComplete(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, ICorDebugEval pEval)
        {
            process.Continue(0);
             
        }

        public void EvalException(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, ICorDebugEval pEval)
        { 
            process.Continue(0);
             
        }

        public void CreateProcess(ICorDebugProcess pProcess)
        {
<<<<<<< .mine
            Console.WriteLine("before stop");
            process.Stop(100);
            Console.WriteLine("we're here");
=======
>>>>>>> .r57
            process.Continue(0);
        }

        public void ExitProcess(ICorDebugProcess pProcess)
        { 
            process.Continue(0);
             
        }

        public void CreateThread(ICorDebugAppDomain pAppDomain, ICorDebugThread thread)
        {
            Console.WriteLine("creating thread");
            process.Continue(0);
             
        }

        public void ExitThread(ICorDebugAppDomain pAppDomain, ICorDebugThread thread)
        {
            process.Continue(0);
             
        }

        public void LoadModule(ICorDebugAppDomain pAppDomain, ICorDebugModule pModule)
        {
            process.Continue(0);
        }

        public void UnloadModule(ICorDebugAppDomain pAppDomain, ICorDebugModule pModule)
        {
            process.Continue(0);
             
        }

        public void LoadClass(ICorDebugAppDomain pAppDomain, ICorDebugClass c)
        { 
            process.Continue(0);
             
        }

        public void UnloadClass(ICorDebugAppDomain pAppDomain, ICorDebugClass c)
        {
            process.Continue(0);
             
        }

        public void DebuggerError(ICorDebugProcess pProcess, int errorHR, uint errorCode)
        {
            process.Continue(0);
             
        }

        public void LogMessage(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, int lLevel,
                               ref ushort pLogSwitchName, ref ushort pMessage)
        { 
            process.Continue(0);
             
        }

        public void LogSwitch(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, int lLevel, uint ulReason,
                              ref ushort pLogSwitchName, ref ushort pParentName)
        {
            process.Continue(0);
             
        }

        public void CreateAppDomain(ICorDebugProcess pProcess, ICorDebugAppDomain pAppDomain)
        {
            pAppDomain.Attach();
            process.Continue(0);
             
        }

        public void ExitAppDomain(ICorDebugProcess pProcess, ICorDebugAppDomain pAppDomain)
        { 
            process.Continue(0);
             
        }

        public void LoadAssembly(ICorDebugAppDomain pAppDomain, ICorDebugAssembly pAssembly)
        {
            process.Continue(0);
             
        }

        public void UnloadAssembly(ICorDebugAppDomain pAppDomain, ICorDebugAssembly pAssembly)
        {
            process.Continue(0);
             
        }

        public void ControlCTrap(ICorDebugProcess pProcess)
        {
            process.Continue(0);
             
        }

        public void NameChange(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread)
        { 
            process.Continue(0);
             
        }

        public void UpdateModuleSymbols(ICorDebugAppDomain pAppDomain, ICorDebugModule pModule, IStream pSymbolStream)
        {
            process.Continue(0);
             
        }

        public void EditAndContinueRemap(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread,
                                         ICorDebugFunction pFunction, int fAccurate)
        { 
            process.Continue(0);
             
        }

        public void BreakpointSetError(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread,
                                       ICorDebugBreakpoint pBreakpoint, uint dwError)
        { 
            process.Continue(0);
             
        }

        public void FunctionRemapOpportunity(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread,
                                             ICorDebugFunction pOldFunction, ICorDebugFunction pNewFunction,
                                             uint oldILOffset)
        { 
            process.Continue(0);
            
        }

        public void CreateConnection(ICorDebugProcess pProcess, uint dwConnectionId, ref ushort pConnName)
        {
            process.Continue(0);

        }

        public void ChangeConnection(ICorDebugProcess pProcess, uint dwConnectionId)
        {
            process.Continue(0);
        }

        public void DestroyConnection(ICorDebugProcess pProcess, uint dwConnectionId)
        {
            process.Continue(0);

        }

        public void Exception(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, ICorDebugFrame pFrame,
                              uint nOffset, CorDebugExceptionCallbackType dwEventType, uint dwFlags)
        {
            process.Continue(0);

        }

        public void ExceptionUnwind(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread,
                                    CorDebugExceptionUnwindCallbackType dwEventType, uint dwFlags)
        {
            process.Continue(0);

        }

        public void FunctionRemapComplete(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread,
                                          ICorDebugFunction pFunction)
        {
            process.Continue(0);

        }

        public void MDANotification(ICorDebugController pController, ICorDebugThread pThread, ICorDebugMDA pMDA)
        { 
            process.Continue(0);

        }
    }
<<<<<<< .mine

    public class B : ICorDebugBreakpoint
    {
        public void Activate(int bActive)
        {
            Console.WriteLine("v activatete");
            // throw new NotImplementedException();
        }

        public void IsActive(out int pbActive)
        {
            pbActive = 1;
            //throw new NotImplementedException();
        }
    }

    //public class T : ICorDebugThread
    //{
    //    public void GetProcess(out ICorDebugProcess ppProcess)
    //    {
    //        throw new NotImplementedException();
    //    }

    //    public void GetID(out uint pdwThreadId)
    //    {
    //        throw new NotImplementedException();
    //    }

    //    public void GetHandle(out uint phThreadHandle)
    //    {
    //        throw new NotImplementedException();
    //    }

    //    public void GetAppDomain(out ICorDebugAppDomain ppAppDomain)
    //    {
    //        throw new NotImplementedException();
    //    }

    //    public void SetDebugState(CorDebugThreadState state)
    //    {
    //        throw new NotImplementedException();
    //    }

    //    public void GetDebugState(out CorDebugThreadState pState)
    //    {
    //        throw new NotImplementedException();
    //    }

    //    public void GetUserState(out CorDebugUserState pState)
    //    {
    //        throw new NotImplementedException();
    //    }

    //    public void GetCurrentException(out ICorDebugValue ppExceptionObject)
    //    {
    //        throw new NotImplementedException();
    //    }

    //    public void ClearCurrentException()
    //    {
    //        throw new NotImplementedException();
    //    }

    //    public void CreateStepper(out ICorDebugStepper ppStepper)
    //    {
    //        throw new NotImplementedException();
    //    }

    //    public void EnumerateChains(out ICorDebugChainEnum ppChains)
    //    {
    //        throw new NotImplementedException();
    //    }

    //    public void GetActiveChain(out ICorDebugChain ppChain)
    //    {
    //        throw new NotImplementedException();
    //    }

    //    public void GetActiveFrame(out ICorDebugFrame ppFrame)
    //    {
    //        throw new NotImplementedException();
    //    }

    //    public void GetRegisterSet(out ICorDebugRegisterSet ppRegisters)
    //    {
    //        throw new NotImplementedException();
    //    }

    //    public void CreateEval(out ICorDebugEval ppEval)
    //    {
    //        throw new NotImplementedException();
    //    }

    //    public void GetObject(out ICorDebugValue ppObject)
    //    {
    //        throw new NotImplementedException();
    //    }
    //}
=======


    */
//>>>>>>> .r57
}
